626D - Jerry's Protest - CodeForces Solution


brute force combinatorics dp probabilities *1800

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>

#define f first
#define s second
#define loop(i, n) for (int i = 0; i < n; ++i)
#define read(a, n) loop($, n) scanf("%d", &a[$]);
#define show(a, n)                  \
    loop($, n) cout << a[$] << " "; \
    cout << endl;

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

// SET WITH INDEXING
// Implements logarithmic find_by_order() and order_of_key()
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

/*  // RANDOM NUMBER GENERATOR
// rng() generates u.a.r. from [0, 2^32 - 1]
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
*/

const int N = 2000;

int a[N], d[N * N];

int main(){
    /*
    auto start = chrono::high_resolution_clock::now();
    */
    
    ios_base::sync_with_stdio(false);   // unsync C- and C++-streams (stdio, iostream)
    cin.tie(NULL);  // untie cin from cout (no automatic flush before read)

    int n; scanf("%d", &n);
    read(a, n);
    sort(a, a + n);
    unordered_map<int, int> cnt;
    int den = 0;
    loop(i, n){
        for(int j = i + 1; j < n; ++j){
            cnt[a[j] - a[i]]++;
            d[den++] = a[j] - a[i];
        }
    }
    sort(d, d + den);
    ull num = 0;
    for(auto it1 = cnt.begin(); it1 != cnt.end(); ++it1){
        for(auto it2 = cnt.begin(); it2 != cnt.end(); ++it2){
            ull w = it1->s * it2->s;
            num += w * (den - (lower_bound(d, d + den, it1->f + it2->f + 1) - d));
        }
    }
    printf("%.10f\n", (double) num / den / den / den);

    /*
    auto stop = chrono::high_resolution_clock::now();
    auto duration = chrono::duration_cast<chrono::microseconds>(stop - start);
    cout << duration.count() << endl;
    */
    return 0;
}


Comments

Submit
0 Comments
More Questions

1213A - Chips Moving
490A - Team Olympiad
233A - Perfect Permutation
1360A - Minimal Square
467A - George and Accommodation
893C - Rumor
227B - Effective Approach
1534B - Histogram Ugliness
1611B - Team Composition Programmers and Mathematicians
110A - Nearly Lucky Number
1220B - Multiplication Table
1644A - Doors and Keys
1644B - Anti-Fibonacci Permutation
1610A - Anti Light's Cell Guessing
349B - Color the Fence
144A - Arrival of the General
1106A - Lunar New Year and Cross Counting
58A - Chat room
230A - Dragons
200B - Drinks
13A - Numbers
129A - Cookies
1367B - Even Array
136A - Presents
1450A - Avoid Trygub
327A - Flipping Game
411A - Password Check
1520C - Not Adjacent Matrix
1538B - Friends and Candies
580A - Kefa and First Steps